<template>
  <div>
    <nav-bar title="巡检登记"></nav-bar>
    <div class="maxinBox">
      <van-form>
        <van-field
          v-model="inspectionName"
          name="巡检点名称"
          label="巡检点名称"
          disabled
        />
        <van-field name="radio" label="巡检结果" v-if="pointDetails && pointDetails.result !== ''">
          <template #input>
            <van-radio-group v-model="form.result" direction="horizontal">
              <van-radio :name='0' v-if="pointDetails && pointDetails.result === 0">正常</van-radio>
              <van-radio :name='1' v-if="pointDetails && pointDetails.result === 1" style="color: red;">异常</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          class="textarea"
          type="textarea"
          v-model="inspectionRequire"
          name="巡检点要求"
          label="巡检点要求"
          disabled
        />
        <van-field
          v-if="!(pointDetails && pointDetails.id && !pointDetails.result)"
          class="textarea marginTop5"
          type="textarea"
          v-model="form.troubleDesc"
          name="巡检描述"
          label="巡检描述"
          required
          placeholder="请输入巡检情况/异常原因"
        />
        <van-cell required title="问题类别" v-model="quistionType" v-if="!(pointDetails && pointDetails.id && !pointDetails.result)" />
        <van-row v-if="pointDetails && pointDetails.result">
          <van-col v-for="(item, index) in images" :key="index" :span="8">
            <div style="padding: 1.25rem 0.625rem">
              <img style="width: 100%;" @click="bigAvatar(item)" :src="item">
            </div>
          </van-col>
        </van-row>
        <van-cell class="marginTop5" title="巡检记录" is-link @click="onWatchmanList" />
      </van-form>
    </div>
  </div>
</template>

<script>
  import realTimeInspectionAPI from '../../../../api/workAPI/realTimeInspectionAPI.js'
  import fixedInspectionApi from '../../../../api/workAPI/fixedInspectionAPI.js'
  import dashbordAPI from '../../../../api/dashbordAPI.js'
  import {ImagePreview} from 'vant'
  export default {
    data() {
      return {
        pointDetails: null,
        images: [],
        form: {
          result: JSON.parse(localStorage.getItem('pointDetails')).result || 0,
          troubleDesc: '',
        },
        quistionType: '',
        inspectionName: JSON.parse(localStorage.getItem('pointDetails')).patrolPointName || '',
        inspectionRequire: JSON.parse(localStorage.getItem('pointDetails')).patrolPointCheckDesc || '',
      }
    },
    methods: {
      // 放大图片
      bigAvatar(img) {
        ImagePreview({
           images: [img],
        })
      },
      // 跳转巡检记录
      onWatchmanList() {
        this.$router.push({
          name: 'InspectionRecord'
        })
      },
    },
    mounted() {
      this.pointDetails = JSON.parse(localStorage.getItem('pointDetails'))
      if (this.pointDetails && this.pointDetails.trouble) {
        this.form.troubleDesc = this.pointDetails.trouble.troubleDesc
        this.quistionType = this.pointDetails.trouble.categoryName
        this.images = this.pointDetails.trouble.reformAttachmentList
      }
    }
  }
</script>

<style scoped lang="scss">
/deep/ .textarea .van-field__control{
  height: 7.5rem
}
</style>
